﻿using NUnit.Framework;
using NUnit.Framework;
using ScrappyDB.Attributes;
using ScrappyDB.BaseClasses;

namespace ScrappyDB.IntegrationTests.Core
{
    
    
    /// <summary>
    ///This is a test class for DBTest and is intended
    ///to contain all DBTest Unit Tests
    ///</summary>
    [TestFixture]
    public class DBDelete
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        //Use ClassCleanup to run code after all tests in a class have run
        [TestFixtureTearDown]
        public static void MyClassCleanup()
        {
            //we shouldn't really have any cleanup after delete test... :-)
        }

        [Test]
        public void DeleteAllTest()
        {
            var db = new Db();

            var a = new SdbCollection<TestEntity>
                        {
                            new TestEntity() {Id = "1", TestString = "test1"},
                            new TestEntity() {Id = "2", TestString = "test2"},
                            new TestEntity() {Id = "3", TestString = "test3"}
                        };
            a.SaveChanges();

            var b = db.Query<TestEntity>(null,true);
            Assert.AreEqual(3, b.Count);

            db.Delete<TestEntity>(b);

            var c = db.Query<TestEntity>(null,true);
            Assert.AreEqual(0, c.Count);
        }

        [DomainName("ScrappyDB_UnitTests"), EntityName("DBDelete_TestEntity")]
        private class TestEntity 
        {
            public string Id { get; set; }
            public string TestString { get; set; }

        }
    }
}
